package hihocode;

import java.util.Scanner;

public class Offer18Problem1 {

	//这道题的关键就是求b关于p的逆元
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()){
			long a = scanner.nextLong();
			long b = scanner.nextLong();
			long p = scanner.nextLong();
			long inv = fermat(b, p);
			System.out.println(a * inv % p);
		}
		scanner.close();
	}
	
	//费马求a关于b的逆元
	private static long fermat(long a, long p){ 
		return quickPowMod(a, p - 2, p);
	}
	
	private static long quickPowMod(long a, long b, long p){
		long res = 1;
		while(b != 0){
			if( (b & 1) != 0){
				res = (res * a) % p;
			}
			a = (a * a) % p;
			b >>= 1;
		}
		return res;
	}
}
